package util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.dati.bean.DatiType;
import com.dati.bean.Xulie;
import com.dati.dao.DatiTypeDao;
import com.dianbo.bean.DianboType;
import com.dianbo.dao.DianboTypeDao;

public class AllTypeList {

	/**
	 *@author qingyu zhang
	 *@function:
	 *2011-4-7
	 *下午02:30:14
	 *zzClub
	 *util
	 */
	public List getLastValue(int userId){
		List list = new ArrayList();
		String condition="userId = "+userId;
	    List<DianboType> dianboTypeList = new ArrayList<DianboType>();
	    dianboTypeList = new DianboTypeDao().getDianboList("tb_qsType_answer", condition, "createTime");
	    
	    /**
	     * 下面得到答题的类型
	     * start!!!!!!!!!!
	     */
	    StringBuffer sb = new StringBuffer();
	    sb.append(" <li class=\"0\"><a>答题类型</a><span title=\"添加答题类型\" class=\"addnode\"><a style=\"cursor:hand\" onclick=\"$mb=$.msgbox({height:220,width:500,content:{type:\'ajax\',content:\'./DatiTypeServlet?method=addType\'},title:\'新增答题类型\'});\">答题类型</a></span><ul class=\"treeview\">");
	    sb.append(getDatiType(userId));
	    sb.append("</ul></li>");
	    list.add(dianboTypeList);
	    list.add(sb);
	    return list;
	}
	/**
	 * 
	 *@author qingyu zhang
	 *@function:在下行积分设置时得到答题、点播的类型
	 * @param userId
	 * @return
	 *2011-4-9
	 *下午09:49:06
	 *zzClub
	 *util
	 *List
	 */
	public List getDownValue(int userId){
		List list = new ArrayList();
		String condition="userId = "+userId;
		List<DianboType> dianboTypeList = new ArrayList<DianboType>();
		dianboTypeList = new DianboTypeDao().getDianboList("tb_qsType_answer", condition, "createTime");
		
		/**
		 * 下面得到答题的类型
		 * start!!!!!!!!!!
		 */
		String conditionT = "userId="+userId;
		List<DatiType> datiTypeList = new ArrayList<DatiType>();
		datiTypeList = new DatiTypeDao().getAllDaTiType("tb_answer_type", "createTime", conditionT);
		list.add(dianboTypeList);
		list.add(datiTypeList);
		return list;
	}
	
    public StringBuffer getDatiType(int userId){
		StringBuffer sb = new StringBuffer();
		String condition=" userId= "+userId;
		List<DatiType> datiTypeList = new ArrayList<DatiType>();
		datiTypeList = new DatiTypeDao().getAllDaTiType("tb_answer_type", "createTime", condition);
		if(datiTypeList!=null&&datiTypeList.size()>0){
			for(DatiType datiType:datiTypeList){
				sb.append(" <li class=\""+datiType.getAnswerTypeId()+"\"><a>"+datiType.getTypeName()+"</a>");
				sb.append("<span title=\"修改类型\" class=\"editnode\"><a style=\"cursor:hand\" onclick=\"$mb=$.msgbox({height:220,width:500,content:{type:\'ajax\',content:\'./DatiTypeServlet?method=modifyType&typeId="+datiType.getAnswerTypeId()+"\'},title:\'修改类型\',onAjaxed: function(data){}});\">修改类型</a></span>");
				sb.append("<span title=\"删除类型\" class=\"delnode\"><a style=\"cursor:hand\" onclick=\"deleteDatiType('../DatiTypeServlet?method=deleteType&typeId="+datiType.getAnswerTypeId()+"')\">删除类型</a></span>");
				sb.append("<span title=\"新增系列\" class=\"addnode\"><a style=\"cursor:hand\" onclick=\"$mb=$.msgbox({height:220,width:500,content:{type:\'ajax\',content:\'./DatiTypeServlet?method=addXiLie&typeId="+datiType.getAnswerTypeId()+"\'},title:\'新增系列\',onAjaxed: function(data){}});\">系列</a></span>");
				String conditionT=" answerTypeId ='"+datiType.getAnswerTypeId()+"'";
				List<Xulie> xulieList = new DatiTypeDao().getXulieByTypeId("tb_serise", "createTime", conditionT);
				if(xulieList!=null&&xulieList.size()>0){
					sb.append(" <ul class=\"treeview\">");
					for(Xulie xulie:xulieList){
						sb.append("<li class=\""+xulie.getSeriseId()+"\"><a>"+xulie.getSeriseName()+"</a>");
						sb.append("<span title=\"修改系列\" class=\"editnode\"><a style=\"cursor:hand\" onclick=\"$mb=$.msgbox({height:220,width:500,content:{type:\'ajax\',content:\'./DatiTypeServlet?method=modifyXilie&xilieId="+xulie.getSeriseId()+"&num="+new Random().nextInt(10000)+"\'},title:\'修改系列\',onAjaxed: function(data){}});\">修改系列</a></span>");
						sb.append("<span title=\"删除系列\" class=\"delnode\"><a style=\"cursor:hand\" onclick=\"deleteXilie('../DatiTypeServlet?method=deleteXilie&xilieId="+xulie.getSeriseId()+"&num="+new Random().nextInt(10000)+"')\">删除系列</a></span>");
						sb.append("<span title=\"设置积分\" class=\"editnode\"><a style=\"cursor:hand\" onclick=\"mb=$.msgbox({height:220,width:500,content:{type:\'iframe\',content:\'./DatiTypeServlet?method=setJiFen&xilieId="+xulie.getSeriseId()+"\'},title:\'设置积分\',onAjaxed: function(data){}});\">设置积分</a></span></li>");
					}
					sb.append("</ur>");
				}
				sb.append("</li>");
			}
		}
		
		System.out.println("sb==="+sb.toString());
		return sb;
	}
}
